<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.data.form = null;
vue.data.disabled = false;
vue.data.api_recordcount = {};
vue.data.api_recordcount.selects = {};
vue.methods.submit_recordcount = function () {
    const that = this;
    //that.disabled = true;
    that.ApiPost('/panel/ua/recordcount.php', that.form).then(function (data) {
        vue.data.api_recordcount = data.data;
        const selects = data.data.selects;
        if (vue.data.form === null) {
            vue.data.form = {};
            for (var key in selects) {
                vue.data.form[key] = '';
            }
        }
    }, function (data) {
        console.log('reject:', data);
    }).catch(function (reason) {
        console.log('catch:', reason);
    })
};
vue.methods.button_delete = function () {
    const that = this;
    if (!confirm('确定要批量删除 ' + this.api_recordcount.sumrecords + ' 条数据吗？')) return;
    //that.disabled = true;
    that.ApiPost('/panel/ua/recordcount_del.php', that.form).then(function (data) {
        for (var key in that.form) {
            that.form[key] = '';
        }
        vue.methods.submit_recordcount();
    }, function (data) {
        console.log('reject:', data);
    }).catch(function (reason) {
        console.log('catch:', reason);
    })

};
vue.methods.button_template = function () {
    const that = this;
    that.ApiPost('/panel/ua/template_add.php', that.form).then(function (data) {
    }, function (data) {
    })

};
vue.mounted = function () {
    vue.methods.submit_recordcount();
};
</script><?php }?>

<!-- Custom Tabs -->
<form v-on:submit="submit_recordcount" onsubmit="return false" :disabled="disabled">
<div class="nav-tabs-custom">

    <label style="margin: 10px;" v-for="(select,key) in api_recordcount.selects">
        {{select.title}}:<select v-model="form[key]" v-on:change="submit_recordcount">
        <option value="">(全部)</option>
        <option v-for="(count,name) in select.options" :value="name">{{name}}({{count}})</option>
    </select></label>
    <button style="font-size: 14px;" class="btn btn-default btn-xs" type="button" v-on:click="button_delete();">批量删除{{api_recordcount.sumrecords}}条</button>

    <button style="font-size: 14px;" class="btn btn-default btn-xs" type="button" v-on:click="button_template();">对{{api_recordcount.sumrecords}}条生成模板</button>



    <div v-for="row in api_recordcount.rows">
        <input :value="row.useragent" style="width: 100%" readonly /><br />
    </div>
</div>
</form>
